public class Solution {
    public int minimumDeletions(int[] nums) {
        int len = nums.length;
        int MaxI = FindMax(nums);
        int MinI = FindMin(nums);
        int max = Math.max(MaxI, MinI);
        int min = Math.min(MaxI, MinI);
        if (max == min) {
            return 1;
        } else {
            return Math.min((min + 1) + (len - max), Math.min(max + 1, len - min));
        }
    }
    public int FindMax(int[] nums){
        int MaxI = 0;
        for(int i = 0;i < nums.length;i ++){
            if(nums[i] > nums[MaxI]){
                MaxI = i;
            }
        }
        return MaxI;
    }
    public int FindMin(int[] nums){
        int MinI = 0;
        for(int i = 0;i < nums.length;i ++){
            if(nums[i] < nums[MinI]){
                MinI = i;
            }
        }
        return MinI;
    }
}